<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>基本资料</title>
  <!-- 导入layui样式 -->
  <link rel="stylesheet" href="../assets/lib/layui/css/layui.css">
  <link rel="stylesheet" href="../assets/css/user/user_info.css">
</head>

<body>
  <div class="layui-card">
    <div class="layui-card-header">重置密码</div>
    <div class="layui-card-body">
      <!-- form表单区域 -->
      <form class="layui-form" lay-filter="formUserIfo" id="user_form">
        <!-- 这是隐藏的id输入框 -->
        <input type="hidden" name="id" value="">
        <!-- 原密码 -->
        <div class="layui-form-item">
          <label class="layui-form-label">原密码</label>
          <div class="layui-input-block">
            <input type="text" name="oldPwd" required lay-verify="required|pwd" placeholder="请输入原密码" autocomplete="off"
              class="layui-input">
          </div>
        </div>
        <!-- 新密码-->
        <div class="layui-form-item">
          <label class="layui-form-label">新密码</label>
          <div class="layui-input-block">
            <input type="password" name="newPwd" required lay-verify="required|pwd|repwd" placeholder="请输入新密码"
              autocomplete="off" class="layui-input">
          </div>
        </div>
        <!-- 确认新密码 -->
        <div class="layui-form-item">
          <label class="layui-form-label">确认新密码</label>
          <div class="layui-input-block">
            <input type="password" name="renewPwd" required lay-verify="required|pwd|somepwd" placeholder="请确认新密码"
              autocomplete="off" class="layui-input">
          </div>
        </div>
        <!-- 提交和重置 -->
        <div class="layui-form-item">
          <div class="layui-input-block">
            <button type="submit" class="layui-btn" lay-submit lay-filter="formDemo">提交修改</button>
            <button type="submit" class="layui-btn layui-btn-primary" id="btnReset">重置</button>
          </div>
        </div>
      </form>
    </div>
  </div>

  <!-- 导入layui。js -->
  <script src="../assets/lib/layui/layui.all.js"></script>
  <!-- 导入jquery -->
  <script src="../assets/lib/jquery.js"></script>
  <!-- 导入自己的js -->
  <script src="../assets/js/user_info.js"></script>
  <!-- 导入baseAPI.js -->
  <script src="../assets/js/mybaseAPI.js"></script>
  <script>
    var layer = layui.layer
    // 通过form.verify()寒素自定义校验规则
    form.verify({
      pwd: [/^[\S]{6,12}$/], // '密码必须6到12位，且不能出现空格'
      // 校验两次密码是否一致
      repwd: function (value) {
        // 通过形参拿到的是确认密码框的值value
        // pwd原密码的input输入框
        //[name=password] 找一个元素，它的属性名为name，属性值为password
        let pwd = $('[name=oldpwd]').val()
        // 然后进行一次等于的判断
        // 如果判断失败，则return一个提示消息即可

        if (pwd === value) {
          return '新旧密码不能相同'
        }

      },
      // 判断两次密码是否相同
      somepwd: function (value) {
        // 获取新密码中的input框的值
        let pwd = $('[name=newpwd]').val()
        if (pwd !== value) {
          return '两次密码不一致'
        }
      }
    })
  </script>
</body>

</html>